<!DOCTYPE html>
<meta charset="utf-8" />
<style type="text/css">
.table-header {
    background-color: #46A3FF;
    color: #fff;
    font-size: 14px;
    line-height: 38px;
    margin-bottom: 1px;
    padding-left: 12px;
}

</style>
<div class="rowt" >
	<div class="col-xs-12">
		<div>
			<table id="sample-table-1" class="table table-striped table-bordered table-hover" >
				<thead>
					<tr>
						<th class="center">
							<label class="position-relative">
								<input type="checkbox" class="ace" id="checkboxlbl1"/>
								<span class="lbl"></span>
							</label>
						</th>
						<th>商户编号</th>
						<th>账户编号</th>
						<th>账户类型</th>
						<th>货币类型</th>
						<th>总余额</th>
						<th>可用余额</th>
						<th>T+1当天金额</th>
						<th>T+1未结算金额</th>
						<th>冻结金额</th>
						<th>最后交易时间</th>
						<th>是否冻结</th>
						<th>操作</th>
					</tr>
				</thead>

				<tbody id="mybody1">
				</tbody>
			
			</table>
		</div>
		<ul class="pagination pull-right no-margin" id="paging_bar_1"></ul>
	</div>
</div>

<script type="text/javascript">
	var pageSize=7;
	var bodycp1=0;
	$(document).ready(function() {
		$("#checkboxlbl1").change(function(){  
			var is_checked =$("#checkboxlbl1").is(":checked");
			$("input[name='mybody1paging_bar_1']").each(function(){
				this.checked=is_checked;
			}); 
		});
		getjson("mpomng/custAccountManage/queryList.do",1,"mybody1","paging_bar_1");
	});

	function getjson(url,cp,body,bar){
		var dialog=$("#dlg-custAccountView").Dialog();
		 $.ajax({
			 type:"post",
			 dataType:"json",
			 url:url,
			 data: {pageSize:pageSize,currentPages:cp,custId:dialog.pageParam.custId},
			 success : function(result) {
					if (result.rspcod != 200) {
						msg.alert("错误", result.rspmsg + " 错误代码："+ result.rspcod, 'error');
					} else {
						if(bodycp1!=0){
							$("#"+body+" tr").remove();
							$("#"+bar+" a").remove();
						}
						
						var pagecount = Math.ceil(result.records/pageSize);
						
						var paging_bar='<li><a href="javascript:void(0)">共 '+result.records+' 条</a>';
						
						paging_bar+='<li class="prev '+(cp<=1?'disabled':'')+'"><a href="javascript:void(0)" onclick=\'getjson(\"'+url+'\",1,\"'+body+'\",\"'+bar+'\");\'>首页</a>';
						for(var i=1;i<=pagecount;i++){
							paging_bar+='<li class="'+(cp==i?'active':'')+'"><a href="javascript:void(0)" onclick=\'getjson(\"'+url+'\",'+i+',\"'+body+'\",\"'+bar+'\");\'>'+i+'</a>';
						}
						paging_bar+='<li class="next '+(cp==pagecount||pagecount==0?'disabled':'')+'"><a href="javascript:void(0)" onclick=\'getjson(\"'+url+'\",'+pagecount+',\"'+body+'\",\"'+bar+'\");\'>尾页</a>';
						$("#"+bar).append(paging_bar);
						
						if(result.obj==null||result.obj=='null'){
							return false;
						}
						$.each(jQuery.parseJSON(result.obj),function(index,obj){
							//alert(obj.accountStatus);
							var inputVal=obj.custId;
							var tr ='<tr><td class="center"><label class="position-relative">'+	
							'<input value="'+inputVal+'" type="checkbox" name="'+(body+bar)+'" class="ace"  /><span class="lbl"></span></label></td>'+
							'<td>'+obj.custId+'</td>'+
							'<td>'+obj.account+'</td>'+
							'<td>'+DICT.get("ACTYPE")[obj.acType]+'</td>'+
							'<td>'+(DICT.get("CURRENCYCODE")[obj.ccy]||'')+'</td>'+
							'<td>'+cent2Yuan(obj.acBal==null?0:obj.acBal)+'</td>'+
							'<td>'+cent2Yuan(obj.acT0==null?0:obj.acT0)+'</td>'+
							'<td>'+cent2Yuan(obj.acT1==null?0:obj.acT1)+'</td>'+
							'<td>'+cent2Yuan(obj.acT1Y==null?0:obj.acT1Y)+'</td>'+
							'<td>'+cent2Yuan(obj.frozBalance==null?0:obj.frozBalance)+'</td>'+
							'<td>'+(obj.lstTxDatetime==null?'':obj.lstTxDatetime)+'</td>'+
							'<td>'+(obj.accountStatus=='0'?'冻结':'正常')+'</td>'+
							'<td><div class=\"hidden-sm hidden-xs btn-group\"><button onClick=\"editStatus(\''+obj.custId+'\',\''+obj.account+'\',\''+(obj.accountStatus=='0'?'1':'0')+'\');\" class=\"btn btn-xs btn-warning\"  title=\"\"">'+
							(obj.accountStatus=='1'?'冻结':'解冻')+'</button>' +
							(obj.acType=='02' && obj.acT1Y > 0 ?'<button onClick=\"T1ToT0(\''+obj.custId+'\',\''+obj.account+'\');\" class=\"btn btn-xs btn-warning\"  title=\"\"">T1入账</button>':'')
							+
							'</div></td></tr>';
							$("#"+body).append(tr);
						});
						bodycp1=cp;
					}
				},
			 error : function(XMLHttpRequest, textStatus) {
					msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："+ textStatus, 'error');
				}
		 });
	}
  
	function editStatus(custId,account,status){
		var agentOrgMer="";
		if(custId.length<=0){
			alertMsg.error('请选择需要冻结的账户');
			return false;
		}
		
		msg.confirm({title:'确认',position:'center',msg:'您确定要冻结/解冻该账户吗？',call:function(ok){
			if(ok){
				$.ajax({
					 type:"post",
					 dataType:"json",
					 async:false,
					 url:"mpomng/custAccountManage/editStatus.do",
					 data: {"custId":custId,"status":status,"account":account},
					 success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："+ result.rspcod, 'error');
							} else {
								getjson("mpomng/custAccountManage/queryList.do",1,"mybody1","paging_bar_1");
							}
						},
					 error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："+ textStatus, 'error');
						}
				});

			}
		}});
	}
	
	function T1ToT0(custId,account){
		var agentOrgMer="";
		if(!custId || !account){
			alertMsg.error('请选择需要操作的账户');
			return false;
		}
		
		msg.confirm({title:'确认',position:'center',msg:'您确定要操作该账户T1余额入账为可用余额吗？',call:function(ok){
			if(ok){
				$.ajax({
					 type:"post",
					 dataType:"json",
					 async:false,
					 url:"mpomng/custAccountManage/t1InAccount.do",
					 data: {"custId":custId,"account":account},
					 success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："+ result.rspcod, 'error');
							} else {
								getjson("mpomng/custAccountManage/queryList.do",1,"mybody1","paging_bar_1");
							}
						},
					 error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："+ textStatus, 'error');
						}
				});

			}
		}});
	}
</script>